package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author rookie001
 * @creat 2023-04-25-9:38
 */
@Configuration
@Slf4j
public class OssConfiguration {
    @Bean//注入第三方bean 将方法的返回值注入
    @ConditionalOnMissingBean//只创建一个对象放入ioc
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){//@auto_wired 自动装配可以省略

        log.info("开始创建阿里云文件上传工具类对象：{}",aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}
